package cn.acheng1314.springboot2.controller

import cn.acheng1314.springboot2.dto.HouseNewsDTO
import cn.acheng1314.springboot2.dto.HouseOtherPropertyDTO
import cn.acheng1314.springboot2.dto.HousePropertyDTO
import cn.acheng1314.springboot2.entity.HouseNews
import cn.acheng1314.springboot2.entity.HouseOtherProperty
import cn.acheng1314.springboot2.entity.HouseProperty
import cn.acheng1314.springboot2.model.ResponseWrap
import cn.acheng1314.springboot2.service.IHouseNewsService
import cn.acheng1314.springboot2.service.IHouseOtherPropertyService
import cn.acheng1314.springboot2.service.IHousePropertyService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*

/**
 * 房源信息相关
 */
@Api(description = "后台房源信息管理")
@RestController
@RequestMapping("/house")
class HouseController {

    private val log = LoggerFactory.getLogger(this::class.java)

    @Autowired
    private lateinit var housePropertyServiceImpl: IHousePropertyService
    @Autowired
    private lateinit var houseOtherPropertyServiceImpl: IHouseOtherPropertyService
    @Autowired
    private lateinit var houseNewsService: IHouseNewsService

    @PostMapping(path = ["/saveHouse"], produces = [(MediaType.APPLICATION_JSON_VALUE)])
    @ResponseBody
    @ApiOperation(value = "保存房源")
    fun saveHouse(@RequestBody house: HousePropertyDTO): ResponseWrap<HouseProperty> {
        val data = housePropertyServiceImpl.saveHouseProperty(house)
        return ResponseWrap<HouseProperty>().warp(data, "保存房源信息成功！")
    }

    @PostMapping(path = ["/saveHouseExtend"], produces = [(MediaType.APPLICATION_JSON_VALUE)])
    @ResponseBody
    @ApiOperation(value = "保存房源扩展信息")
    fun saveHouseExtend(@RequestBody house: HouseOtherPropertyDTO): ResponseWrap<HouseOtherProperty> {
        val data = houseOtherPropertyServiceImpl.saveOtherProperty(house)
        return ResponseWrap<HouseOtherProperty>().warp(data, "保存房源扩展信息成功！")
    }

    @PostMapping(path = ["/saveHouseNews"], produces = [(MediaType.APPLICATION_JSON_VALUE)])
    @ResponseBody
    @ApiOperation(value = "保存房源新闻信息")
    fun saveHouseNews(@RequestBody dto: HouseNewsDTO): ResponseWrap<HouseNews> {
        val data = houseNewsService.addHouseNews(dto)
        return ResponseWrap<HouseNews>().warp(data, "保存房源新闻信息成功！")
    }


}